<?php

namespace app\admin\model;

use app\common\model\TimeModel;

class PicturePictures extends TimeModel
{

    protected $name = "picture_pictures";

    protected $deleteTime = false;


    public function cate()
    {
        return $this->belongsTo('app\admin\model\PictureCate', 'cate_id', 'id');
    }

    /**
     * @param int    $page
     * @param array  $where
     * @param string $order
     * @param string $group
     * @param int    $limit
     *
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getList($page=1,$where=[],$order='create_time desc', $group = 'upload_time',$limit = 10)
    {
        $count = self::where($where)->group($group)->count('id');
        $total_page = intval(ceil($count/ $limit));
        $list = self::where($where)
            ->field('id,upload_time')
            ->group($group)
            ->order($order)
            ->page($page, $limit)
            ->select();
        foreach ($list as &$v){
            $v['mouth'] = date('m',$v->getData('upload_time'));
            $v['day'] = date('d',$v->getData('upload_time'));
            $v['images'] = self::where($where)->where('upload_time',$v->getData('upload_time'))->select();
        }
        return compact('count', 'total_page', 'list');
    }
}